package com.orange.adminapi.job;

import com.orange.core.pojo.entity.coupon.Coupon;
import com.orange.core.service.coupon.CouponService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

@Slf4j
@RequiredArgsConstructor
@Component
public class CouponTaskJobHandler {

    private final CouponService couponService;

    /**
     * 优惠券过期下架
     */
    @XxlJob("couponExpiredShelfOff")
    public ReturnT<String> couponExpiredShelfOff(String param) {
        log.info("开始执行优惠券过期下架任务");
        couponService.lambdaUpdate()
                .set(Coupon::getShelf, 0)
                .eq(Coupon::getShelf, 1)
                .lt(Coupon::getEffectEnd, LocalDate.now())
                .update();
        log.info("优惠券过期下架任务完成");
        return ReturnT.SUCCESS;
    }
}
